home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 3.iso / dist / fw_apache.idb / usr / freeware / apache / include / buff.h.z / buff.h
C/C++ Source or Header  |  2001-01-10  |  8KB  |  245 lines

  1. /* ====================================================================
  2.  * Copyright (c) 1996-1999 The Apache Group.  All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer. 
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by the Apache Group
  19.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  20.  *
  21.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  22.  *    endorse or promote products derived from this software without
  23.  *    prior written permission. For written permission, please contact
  24.  *    apache@apache.org.
  25.  *
  26.  * 5. Products derived from this software may not be called "Apache"
  27.  *    nor may "Apache" appear in their names without prior written
  28.  *    permission of the Apache Group.
  29.  *
  30.  * 6. Redistributions of any form whatsoever must retain the following
  31.  *    acknowledgment:
  32.  *    "This product includes software developed by the Apache Group
  33.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  36.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  38.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  46.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Group and was originally based
  51.  * on public domain software written at the National Center for
  52.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  53.  * For more information on the Apache Group and the Apache HTTP server
  54.  * project, please see <http://www.apache.org/>.
  55.  *
  56.  */
  57.  
  58. #ifndef APACHE_BUFF_H
  59. #define APACHE_BUFF_H
  60.  
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64.  
  65. #ifdef B_SFIO
  66. #include "sfio.h"
  67. #endif
  68.  
  69. #include <stdarg.h>
  70.  
  71. /* Reading is buffered */
  72. #define B_RD     (1)
  73. /* Writing is buffered */
  74. #define B_WR     (2)
  75. #define B_RDWR   (3)
  76. /* At end of file, or closed stream; no further input allowed */
  77. #define B_EOF    (4)
  78. /* No further output possible */
  79. #define B_EOUT   (8)
  80. /* A read error has occurred */
  81. #define B_RDERR (16)
  82. /* A write error has occurred */
  83. #define B_WRERR (32)
  84. #ifdef B_ERROR  /* in SVR4: sometimes defined in /usr/include/sys/buf.h */
  85. #undef B_ERROR
  86. #endif
  87. #define B_ERROR (48)
  88. /* Use chunked writing */
  89. #define B_CHUNK (64)
  90. /* bflush() if a read would block */
  91. #define B_SAFEREAD (128)
  92. /* buffer is a socket */
  93. #define B_SOCKET (256)
  94. #ifdef CHARSET_EBCDIC
  95. #define B_ASCII2EBCDIC 0x40000000  /* Enable conversion for this buffer */
  96. #define B_EBCDIC2ASCII 0x80000000  /* Enable conversion for this buffer */
  97. #endif /*CHARSET_EBCDIC*/
  98.  
  99. typedef struct buff_struct BUFF;
  100.  
  101. struct buff_struct {
  102.     int flags;            /* flags */
  103.     unsigned char *inptr;    /* pointer to next location to read */
  104.     int incnt;            /* number of bytes left to read from input buffer;
  105.                  * always 0 if had a read error  */
  106.     int outchunk;        /* location of chunk header when chunking */
  107.     int outcnt;            /* number of byte put in output buffer */
  108.     unsigned char *inbase;
  109.     unsigned char *outbase;
  110.     int bufsiz;
  111.     void (*error) (BUFF *fb, int op, void *data);
  112.     void *error_data;
  113.     long int bytes_sent;    /* number of bytes actually written */
  114.  
  115.     ap_pool *pool;
  116.  
  117. /* could also put pointers to the basic I/O routines here */
  118.     int fd;            /* the file descriptor */
  119.     int fd_in;            /* input file descriptor, if different */
  120. #ifdef WIN32
  121.     HANDLE hFH;            /* Windows filehandle */
  122. #endif
  123.  
  124.     /* transport handle, for RPC binding handle or some such */
  125.     void *t_handle;
  126.  
  127. #ifdef EAPI
  128.     ap_ctx *ctx;
  129. #endif /* EAPI */
  130.  
  131. #ifdef B_SFIO
  132.     Sfio_t *sf_in;
  133.     Sfio_t *sf_out;
  134. #endif
  135. };
  136.  
  137. #ifdef B_SFIO
  138. typedef struct {
  139.     Sfdisc_t disc;
  140.     BUFF *buff;
  141. } apache_sfio;
  142.  
  143. extern Sfdisc_t *bsfio_new(pool *p, BUFF *b);
  144. #endif
  145.  
  146. /* Options to bset/getopt */
  147. #define BO_BYTECT (1)
  148.  
  149. /* Stream creation and modification */
  150. API_EXPORT(BUFF *) ap_bcreate(pool *p, int flags);
  151. API_EXPORT(void) ap_bpushfd(BUFF *fb, int fd_in, int fd_out);
  152. #ifdef WIN32
  153. API_EXPORT(void) ap_bpushh(BUFF *fb, HANDLE hFH);
  154. #endif
  155. API_EXPORT(int) ap_bsetopt(BUFF *fb, int optname, const void *optval);
  156. API_EXPORT(int) ap_bgetopt(BUFF *fb, int optname, void *optval);
  157. API_EXPORT(int) ap_bsetflag(BUFF *fb, int flag, int value);
  158. API_EXPORT(int) ap_bclose(BUFF *fb);
  159.  
  160. #define ap_bgetflag(fb, flag)    ((fb)->flags & (flag))
  161.  
  162. /* Error handling */
  163. API_EXPORT(void) ap_bonerror(BUFF *fb, void (*error) (BUFF *, int, void *),
  164.               void *data);
  165.  
  166. /* I/O */
  167. API_EXPORT(int) ap_bread(BUFF *fb, void *buf, int nbyte);
  168. API_EXPORT(int) ap_bgets(char *s, int n, BUFF *fb);
  169. API_EXPORT(int) ap_blookc(char *buff, BUFF *fb);
  170. API_EXPORT(int) ap_bskiplf(BUFF *fb);
  171. API_EXPORT(int) ap_bwrite(BUFF *fb, const void *buf, int nbyte);
  172. API_EXPORT(int) ap_bflush(BUFF *fb);
  173. API_EXPORT(int) ap_bputs(const char *x, BUFF *fb);
  174. API_EXPORT(int) ap_bvputs(BUFF *fb,...);
  175. API_EXPORT_NONSTD(int) ap_bprintf(BUFF *fb, const char *fmt,...)
  176.                 __attribute__((format(printf,2,3)));
  177. API_EXPORT(int) ap_vbprintf(BUFF *fb, const char *fmt, va_list vlist);
  178.  
  179. /* Internal routines */
  180. API_EXPORT(int) ap_bflsbuf(int c, BUFF *fb);
  181. API_EXPORT(int) ap_bfilbuf(BUFF *fb);
  182.  
  183. #ifdef EAPI
  184. #define ap_bpeekc(fb) ( ((fb)->incnt == 0) ? EOF : *((fb)->inptr) )
  185. #endif
  186.  
  187. #ifndef CHARSET_EBCDIC
  188.  
  189. #define ap_bgetc(fb)   ( ((fb)->incnt == 0) ? ap_bfilbuf(fb) : \
  190.             ((fb)->incnt--, *((fb)->inptr++)) )
  191.  
  192. #define ap_bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
  193.              (fb)->outcnt == (fb)->bufsiz) ? ap_bflsbuf(c, (fb)) : \
  194.              ((fb)->outbase[(fb)->outcnt++] = (c), 0))
  195.  
  196. #else /*CHARSET_EBCDIC*/
  197.  
  198. #define ap_bgetc(fb)   ( ((fb)->incnt == 0) ? ap_bfilbuf(fb) : \
  199.             ((fb)->incnt--, (fb->flags & B_ASCII2EBCDIC)\
  200.             ?os_toebcdic[(unsigned char)*((fb)->inptr++)]:*((fb)->inptr++)) )
  201.  
  202. #define ap_bputc(c, fb) ((((fb)->flags & (B_EOUT|B_WRERR|B_WR)) != B_WR || \
  203.              (fb)->outcnt == (fb)->bufsiz) ? ap_bflsbuf(c, (fb)) : \
  204.              ((fb)->outbase[(fb)->outcnt++] = (fb->flags & B_EBCDIC2ASCII)\
  205.              ?os_toascii[(unsigned char)c]:(c), 0))
  206.  
  207. #endif /*CHARSET_EBCDIC*/
  208. struct child_info {
  209. #ifdef WIN32
  210.     /*
  211.      *  These handles are used by ap_call_exec to call 
  212.      *  create process with pipe handles.
  213.      */
  214.     HANDLE hPipeInputRead;
  215.     HANDLE hPipeOutputWrite;
  216.     HANDLE hPipeErrorWrite;
  217. #else
  218.     /* 
  219.      * We need to put a dummy member in here to avoid compilation
  220.      * errors under certain Unix compilers, like SGI's and HPUX's,
  221.      * which fail to compile a zero-sized struct.  Of course
  222.      * it would be much nicer if there was actually a use for this
  223.      * structure under Unix.  Aah the joys of x-platform code.
  224.      */
  225.     int dummy;
  226. #endif
  227. };
  228. API_EXPORT(int) ap_bspawn_child(pool *, int (*)(void *, child_info *), void *,
  229.                     enum kill_conditions, BUFF **pipe_in, BUFF **pipe_out,
  230.                     BUFF **pipe_err);
  231.  
  232. /* enable non-blocking operations */
  233. API_EXPORT(int) ap_bnonblock(BUFF *fb, int direction);
  234. /* and get an fd to select() on */
  235. API_EXPORT(int) ap_bfileno(BUFF *fb, int direction);
  236.  
  237. /* bflush() if a read now would block, but don't actually read anything */
  238. API_EXPORT(void) ap_bhalfduplex(BUFF *fb);
  239.  
  240. #ifdef __cplusplus
  241. }
  242. #endif
  243.  
  244. #endif    /* !APACHE_BUFF_H */
  245.